In [1]:
import pickle
import pandas as pd
import os
In [2]:
os.chdir("/Users/vivek/myCode/company/i18r/tykhe")
In [3]:
df = pd.read_csv("data/01-Feb-2019/cleaned/features/derived/specific/indexData/NIFTY_50_Close-dpc.csv")
df['Date'] = pd.to_datetime(df['Date'], format='%Y-%m-%d')
df = df.set_index("Date")
index = df.index
index = index.tz_localize(tz='UTC')
df = df.set_index(index)
In [4]:
def loadResults(date):
    name = "saves/" + str(date) + "/" + str(date) + ".pkl"
    with open(name, 'rb') as f:
        # The protocol version used is detected automatically, so we do not
        # have to specify it.
        data = pickle.load(f)
    return data
In [9]:
result = loadResults("2012-04-01")
benchmark = df.loc["2012-04-01":"2013-03-31"]["NIFTY_50_Close-dpc"]/100
(returns, positions, transactions, gross_lev) = result['PyFolio_items']
import pyfolio as pf
pf.create_full_tear_sheet(
            returns,
            positions=None,
            transactions=None,
            live_start_date=None,
            round_trips=True,
            benchmark_rets=benchmark,
            turnover_denom='portfolio_value')
Start date2012-04-01
End date2013-03-31
Total months17
Backtest
Annual return 12.9%
Cumulative returns 12.9%
Annual volatility 8.1%
Sharpe ratio 1.53
Calmar ratio 2.10
Stability 0.85
Max drawdown -6.1%
Omega ratio 1.39
Sortino ratio 2.63
Skew 1.77
Kurtosis 18.25
Tail ratio 1.07
Daily value at risk -0.8%
Alpha 0.09
Beta 0.39
/Users/vivek/anaconda3/envs/i18r/lib/python3.6/site-packages/numpy/core/fromnumeric.py:51: FutureWarning: 'argmin' is deprecated, use 'idxmin' instead. The behavior of 'argmin'
will be corrected to return the positional minimum in the future.
Use 'series.values.argmin' to get the position of the minimum now.
  return getattr(obj, method)(*args, **kwds)
Worst drawdown periods Net drawdown in % Peak date Valley date Recovery date Duration
0 6.11 2012-04-01 2012-06-01 2012-06-12 52
1 2.36 2012-07-05 2012-07-26 2012-08-19 32
2 2.22 2012-06-13 2012-06-18 2012-06-21 7
3 2.14 2012-09-14 2012-12-17 2013-01-11 86
4 1.02 2013-03-07 2013-03-24 NaT NaN
Stress Events mean min max
EZB IR Event -0.00% -0.41% 0.35%
Recovery 0.02% -2.06% 2.90%
New Normal 0.06% -0.30% 2.31%
In [10]:
result = loadResults("2013-04-01")
benchmark = df.loc["2013-04-01":"2014-03-31"]["NIFTY_50_Close-dpc"]/100
(returns, positions, transactions, gross_lev) = result['PyFolio_items']
import pyfolio as pf
pf.create_full_tear_sheet(
            returns,
            positions=None,
            transactions=None,
            live_start_date=None,
            round_trips=True,
            benchmark_rets=benchmark,
            turnover_denom='portfolio_value')
Start date2013-04-01
End date2014-03-31
Total months17
Backtest
Annual return 37.5%
Cumulative returns 37.5%
Annual volatility 11.3%
Sharpe ratio 2.87
Calmar ratio 4.00
Stability 0.95
Max drawdown -9.4%
Omega ratio 1.63
Sortino ratio 5.14
Skew 1.34
Kurtosis 10.82
Tail ratio 1.45
Daily value at risk -1.1%
Alpha 0.25
Beta 0.45
/Users/vivek/anaconda3/envs/i18r/lib/python3.6/site-packages/numpy/core/fromnumeric.py:51: FutureWarning: 'argmin' is deprecated, use 'idxmin' instead. The behavior of 'argmin'
will be corrected to return the positional minimum in the future.
Use 'series.values.argmin' to get the position of the minimum now.
  return getattr(obj, method)(*args, **kwds)
Worst drawdown periods Net drawdown in % Peak date Valley date Recovery date Duration
0 9.36 2013-09-19 2013-09-30 2014-01-10 82
1 3.57 2013-05-17 2013-06-25 2013-07-11 40
2 3.13 2014-01-20 2014-02-09 2014-03-05 33
3 2.69 2013-08-13 2013-08-21 2013-08-28 12
4 1.85 2013-07-12 2013-07-16 2013-07-19 6
Stress Events mean min max
New Normal 0.09% -2.79% 4.39%
In [11]:
result = loadResults("2014-04-01")
benchmark = df.loc["2014-04-01":"2015-03-31"]["NIFTY_50_Close-dpc"]/100
(returns, positions, transactions, gross_lev) = result['PyFolio_items']
import pyfolio as pf
pf.create_full_tear_sheet(
            returns,
            positions=None,
            transactions=None,
            live_start_date=None,
            round_trips=True,
            benchmark_rets=benchmark,
            turnover_denom='portfolio_value')
Start date2014-04-01
End date2015-03-31
Total months17
Backtest
Annual return 12.0%
Cumulative returns 12.0%
Annual volatility 7.8%
Sharpe ratio 1.50
Calmar ratio 2.73
Stability 0.92
Max drawdown -4.4%
Omega ratio 1.27
Sortino ratio 2.20
Skew -0.28
Kurtosis 3.47
Tail ratio 1.28
Daily value at risk -0.8%
Alpha 0.03
Beta 0.34
/Users/vivek/anaconda3/envs/i18r/lib/python3.6/site-packages/numpy/core/fromnumeric.py:51: FutureWarning: 'argmin' is deprecated, use 'idxmin' instead. The behavior of 'argmin'
will be corrected to return the positional minimum in the future.
Use 'series.values.argmin' to get the position of the minimum now.
  return getattr(obj, method)(*args, **kwds)
Worst drawdown periods Net drawdown in % Peak date Valley date Recovery date Duration
0 4.42 2015-01-27 2015-03-26 NaT NaN
1 3.65 2014-04-15 2014-05-19 2014-06-11 42
2 3.56 2014-09-08 2014-10-20 2014-11-21 55
3 2.13 2014-12-04 2014-12-16 2014-12-31 20
4 1.57 2014-07-07 2014-07-15 2014-07-23 13
Stress Events mean min max
Apr14 -0.02% -0.93% 0.55%
Oct14 -0.01% -1.70% 1.04%
New Normal 0.03% -1.70% 1.35%
In [12]:
result = loadResults("2015-04-01")
benchmark = df.loc["2015-04-01":"2016-03-31"]["NIFTY_50_Close-dpc"]/100
(returns, positions, transactions, gross_lev) = result['PyFolio_items']
import pyfolio as pf
pf.create_full_tear_sheet(
            returns,
            positions=None,
            transactions=None,
            live_start_date=None,
            round_trips=True,
            benchmark_rets=benchmark,
            turnover_denom='portfolio_value')
Start date2015-04-01
End date2016-03-31
Total months17
Backtest
Annual return -3.8%
Cumulative returns -3.8%
Annual volatility 9.4%
Sharpe ratio -0.36
Calmar ratio -0.27
Stability 0.60
Max drawdown -14.0%
Omega ratio 0.94
Sortino ratio -0.50
Skew 0.01
Kurtosis 4.09
Tail ratio 0.79
Daily value at risk -1.0%
Alpha 0.01
Beta 0.57
/Users/vivek/anaconda3/envs/i18r/lib/python3.6/site-packages/numpy/core/fromnumeric.py:51: FutureWarning: 'argmin' is deprecated, use 'idxmin' instead. The behavior of 'argmin'
will be corrected to return the positional minimum in the future.
Use 'series.values.argmin' to get the position of the minimum now.
  return getattr(obj, method)(*args, **kwds)
Worst drawdown periods Net drawdown in % Peak date Valley date Recovery date Duration
0 14.02 2015-08-19 2016-02-25 NaT NaN
1 3.02 2015-04-13 2015-06-11 2015-07-16 69
2 2.33 2015-07-22 2015-07-28 2015-08-06 12
3 0.91 2015-08-06 2015-08-12 2015-08-14 7
4 0.12 2015-07-17 2015-07-20 2015-07-21 3
Stress Events mean min max
Fall2015 -0.06% -1.61% 1.39%
New Normal -0.01% -2.08% 2.35%
In [13]:
result = loadResults("2016-04-01")
benchmark = df.loc["2016-04-01":"2017-03-31"]["NIFTY_50_Close-dpc"]/100
(returns, positions, transactions, gross_lev) = result['PyFolio_items']
import pyfolio as pf
pf.create_full_tear_sheet(
            returns,
            positions=None,
            transactions=None,
            live_start_date=None,
            round_trips=True,
            benchmark_rets=benchmark,
            turnover_denom='portfolio_value')
Start date2016-04-01
End date2017-03-31
Total months17
Backtest
Annual return 5.1%
Cumulative returns 5.1%
Annual volatility 5.3%
Sharpe ratio 0.97
Calmar ratio 1.32
Stability 0.41
Max drawdown -3.9%
Omega ratio 1.16
Sortino ratio 1.39
Skew -0.17
Kurtosis 4.27
Tail ratio 1.06
Daily value at risk -0.5%
Alpha 0.01
Beta 0.25
/Users/vivek/anaconda3/envs/i18r/lib/python3.6/site-packages/numpy/core/fromnumeric.py:51: FutureWarning: 'argmin' is deprecated, use 'idxmin' instead. The behavior of 'argmin'
will be corrected to return the positional minimum in the future.
Use 'series.values.argmin' to get the position of the minimum now.
  return getattr(obj, method)(*args, **kwds)
Worst drawdown periods Net drawdown in % Peak date Valley date Recovery date Duration
0 3.86 2016-08-11 2016-11-11 2016-12-30 102
1 2.30 2017-01-04 2017-02-01 2017-02-19 33
2 1.89 2016-04-18 2016-05-06 2016-05-29 30
3 1.64 2016-06-22 2016-07-15 2016-08-01 29
4 1.21 2017-03-16 2017-03-22 2017-03-29 10
Stress Events mean min max
New Normal 0.01% -1.25% 1.43%
In [14]:
result = loadResults("2017-04-01")
benchmark = df.loc["2017-04-01":"2018-03-31"]["NIFTY_50_Close-dpc"]/100
(returns, positions, transactions, gross_lev) = result['PyFolio_items']
import pyfolio as pf
pf.create_full_tear_sheet(
            returns,
            positions=None,
            transactions=None,
            live_start_date=None,
            round_trips=True,
            benchmark_rets=benchmark,
            turnover_denom='portfolio_value')
Start date2017-04-01
End date2018-03-31
Total months17
Backtest
Annual return 10.0%
Cumulative returns 10.0%
Annual volatility 4.4%
Sharpe ratio 2.18
Calmar ratio 2.10
Stability 0.74
Max drawdown -4.7%
Omega ratio 1.63
Sortino ratio 3.95
Skew 1.70
Kurtosis 14.19
Tail ratio 1.43
Daily value at risk -0.4%
Alpha 0.06
Beta 0.29
/Users/vivek/anaconda3/envs/i18r/lib/python3.6/site-packages/numpy/core/fromnumeric.py:51: FutureWarning: 'argmin' is deprecated, use 'idxmin' instead. The behavior of 'argmin'
will be corrected to return the positional minimum in the future.
Use 'series.values.argmin' to get the position of the minimum now.
  return getattr(obj, method)(*args, **kwds)
Worst drawdown periods Net drawdown in % Peak date Valley date Recovery date Duration
0 4.74 2018-01-24 2018-03-23 NaT NaN
1 2.24 2017-09-19 2017-09-27 2017-11-05 34
2 0.86 2017-11-10 2017-12-06 2017-12-08 21
3 0.84 2017-05-26 2017-05-29 2017-06-06 8
4 0.76 2017-12-11 2017-12-13 2017-12-15 5
Stress Events mean min max
New Normal 0.03% -1.17% 1.75%
In [15]:
result = loadResults("2018-02-01")
benchmark = df.loc["2018-02-01":"2019-01-31"]["NIFTY_50_Close-dpc"]/100
(returns, positions, transactions, gross_lev) = result['PyFolio_items']
import pyfolio as pf
pf.create_full_tear_sheet(
            returns,
            positions=None,
            transactions=None,
            live_start_date=None,
            round_trips=True,
            benchmark_rets=benchmark,
            turnover_denom='portfolio_value')
Start date2018-02-01
End date2019-01-31
Total months17
Backtest
Annual return 9.2%
Cumulative returns 9.2%
Annual volatility 8.2%
Sharpe ratio 1.12
Calmar ratio 1.23
Stability 0.63
Max drawdown -7.5%
Omega ratio 1.19
Sortino ratio 1.66
Skew 0.31
Kurtosis 4.51
Tail ratio 0.91
Daily value at risk -0.8%
Alpha 0.09
Beta 0.28
/Users/vivek/anaconda3/envs/i18r/lib/python3.6/site-packages/numpy/core/fromnumeric.py:51: FutureWarning: 'argmin' is deprecated, use 'idxmin' instead. The behavior of 'argmin'
will be corrected to return the positional minimum in the future.
Use 'series.values.argmin' to get the position of the minimum now.
  return getattr(obj, method)(*args, **kwds)
Worst drawdown periods Net drawdown in % Peak date Valley date Recovery date Duration
0 7.48 2018-09-25 2018-10-26 NaT NaN
1 2.12 2018-04-26 2018-05-08 2018-06-13 35
2 1.81 2018-03-12 2018-03-19 2018-04-12 24
3 1.76 2018-02-01 2018-02-19 2018-02-23 17
4 1.16 2018-06-15 2018-06-21 2018-07-03 13
Stress Events mean min max
New Normal 0.02% -1.49% 2.21%